package indi.yangshenhui.spring.controller;

import indi.yangshenhui.spring.pojo.StudentPojo;
import indi.yangshenhui.spring.service.StudentService;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {
	private static final Logger LOGGER = Logger
			.getLogger(LoginController.class);
	@Autowired
	private StudentService studentService;

	@RequestMapping("login.do")
	public String login(@RequestParam(value = "username") String username,
			@RequestParam(value = "password") String password,
			HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		LOGGER.info(username);
		LOGGER.info(password);
		LOGGER.info(request.getRemoteAddr());
		LOGGER.info(response.getCharacterEncoding());
		List<StudentPojo> sList = studentService.query(null, 0, 3);
		for (StudentPojo studentPojo : sList) {
			LOGGER.info(studentPojo);
		}
		return "home";
	}

}